<?php
require_once(OC::$SERVERROOT . "/apps/reports/lib/helper.php");
require_once(OC::$SERVERROOT . "/apps/reports/lib/reports.php");

if (!PFactory::isMasterUser()) {
   echo '您无权访问该资源';
   exit();
}

$start = JRequest::getString('start', '');
$end = JRequest::getString('end', '');
$xtypes = array('job', 'resume', 'event', 'offer', 'entry');

$model = new PReportsModelReports();
$summary = $model->getOneSubaccount();

if ($summary === false) {
   jexit('<div class="yahei large noreportsdata">' . ($model->getError() ? $model->getError() : '系统错误') . '</div>');
}

$statusList = array('resume', 'fgood', 'fbad', 'pending', 'event', 'retest', 'absent', 'egood', 'ebad', 'offer', 'entry');
?>

<div class="rep_allpos">负责<span><?=$summary['jobsCount']?></span>个职位</div>

<div class="rep_resumefrom" style="margin-top:20px;" id="anchor_position">
   <h5><b>流程设置情况</b></h5>

   <div class="clearfix">
      <div id="jobSummaryBar" class="pull-left" style="height:205px; width:60%"></div>

      <div class="rep_detailtable pull-right" style="width:35%; margin-top:10px;">
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
               <th width="34%">流程设置</th>
               <th width="33%">职位数</th>
               <th width="33%">比例</th>
            </tr>
            <tr>
               <td class="medium">已设匹配条件</td>
               <td><?=$summary['details']['interview_setup']['count']?></td>
               <td><?=$summary['details']['interview_setup']['weight']?></td>
            </tr>
            <tr>
               <td class="medium">已设线上笔试</td>
               <td><?=$summary['details']['onlinetest_setup']['count']?></td>
               <td><?=$summary['details']['onlinetest_setup']['weight']?></td>
            </tr>
            <tr>
               <td class="medium">已设性格评测</td>
               <td><?=$summary['details']['persontest_setup']['count']?></td>
               <td><?=$summary['details']['persontest_setup']['weight']?></td>
            </tr>
         </table>
      </div>
   </div>
</div>

<div class="rep_resumefrom" id="anchor_zhaopin">
   <h5><b>招聘情况</b></h5>

   <div class="clearfix">
      <div class="rep_detailtable pull-left" style="width:100%; margin-bottom:15px;">
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
               <th width="%">新增简历</th>
               <th width="%">筛选合格</th>
               <th width="%">筛选不合格</th>
               <th width="%">筛选结果待定</th>
               <th width="%">面试</th>
               <th width="%">复试</th>
               <th width="%">缺席</th>
               <th width="%">面试合格</th>
               <th width="%">面试不合格</th>
               <th width="%">发offer</th>
               <th width="%">入职</th>
            </tr>
            <tr>
               <? foreach ($statusList as $s): ?>
                  <td><?=(!empty($summary['status']['total'][$s]) ? $summary['status']['total'][$s] : 0)?></td>
               <? endforeach; ?>
            </tr>
         </table>
      </div>

      <div class="pull-left" style="width:50%">
         <? if (!empty($summary['prostatus']['pie']['data'])): ?>
            <div id="processPie" style="height:210px; width:410px; margin:4px auto;"></div>
         <? else: ?>
            <div class="nodatacolor" style="text-align: center; margin-top: 70px;">暂无数据</div>
         <? endif; ?>
      </div>

      <div class="rep_detailtable pull-right" style="width:50%; margin-top:10px;">
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
               <th width="44%">简历状态</th>
               <th width="28%">简历数</th>
               <th width="28%">比例</th>
            </tr>
            <tr>
               <td class="medium">已处理<br><span style="color:#999999;">(已加标签 \ 改状态 \ 写备注评语)</span></td>
               <td><?=$summary['prostatus']['total']['processed']['count']?></td>
               <td><?=$summary['prostatus']['total']['processed']['weight']?></td>
            </tr>
            <tr>
               <td class="medium">未处理</td>
               <td><?=$summary['prostatus']['total']['unprocessed']['count']?></td>
               <td><?=$summary['prostatus']['total']['unprocessed']['weight']?></td>
            </tr>
         </table>
      </div>
   </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
   var summary = <?=json_encode($summary)?>;
   var charts = new Array();
   $(window).unbind('resize');
   
   if($("#jobSummaryBar").length > 0) {
      // Can specify a custom tick Array.
      // Ticks should match up one for each y value (category) in the series.
      var ticks = ['已设匹配条件', '已设线上笔试', '已设性格评测'];

      charts[charts.length++] = $.jqplot('jobSummaryBar', [summary.bars.data], {
         seriesColors: [ "#71c5f4"],
         // The "seriesDefaults" option is an options object that will
         // be applied to all series in the chart.
         seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            rendererOptions: {
               fillToZero: true,
               barWidth: 45,
               barMargin: 70
            },
            pointLabels: {show: true},
            showLabel:false,
            shadow:false
         },
         // Custom labels for the series are specified with the "label"
         // option on the series option.  Here a series option object
         // is specified for each series.
         series:[
            {showLabel:false}
         ],
         // Show the legend and put it outside the grid, but inside the
         // plot container, shrinking the grid to accomodate the legend.
         // A value of "outside" would not shrink the grid and allow
         // the legend to overflow the container.
         legend: {
            show: true,
            placement: 'outsideGrid'
         },
         axes: {
            // Use a category axis on the x axis and use our custom ticks.
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            },
            // Pad the y axis just a little so bars can get close to, but
            // not touch, the grid boundaries.  1.2 is the default padding.
            yaxis: {
               min:0,
               max: summary.bars.max,
               tickInterval : summary.bars.tickInterval,
               tickOptions: {formatString: '%d'}
            }
         },
         grid: {
            shadow: false,               // draw a shadow for grid.
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#e9e9e9',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#333333',     // CSS color spec for border around grid.
            borderWidth: 0.5,               // draw a shadow for grid.
         }
      });
   }

   if($("#processPie").length > 0) {
      $.jqplot ('processPie', [summary.prostatus.pie.data], {
         seriesColors: [ "#75ceff", "#e46562"],
         seriesDefaults: {
            // Make this a pie chart.
            renderer: jQuery.jqplot.PieRenderer,
            rendererOptions: {
               startAngle: -180,
               // Put data labels on the pie slices.
               // By default, labels show the percentage of the slice.
               dataLabels: summary.prostatus.pie.labels,
               showDataLabels: true,
               diameter: 118, // diameter of pie, auto computed by default.
               sliceMargin: 2,     // gap between slices.
               fill: true,         // render solid (filled) slices.
               shadow: false,
               shadowOffset: 2,    // offset of the shadow from the chart.
               shadowDepth: 5,     // Number of strokes to make when drawing shadow.  Each stroke
                                   // offset by shadowOffset from the last.
               shadowAlpha: 0.07,   // Opacity of the shadow
               dataLabelPositionFactor:1.4
            }
         },
         // Custom labels for the series are specified with the "label"
         // option on the series option.  Here a series option object
         // is specified for each series.
         series:[
            {showLabel:true,color:'#ffffff'}
         ],
         legend: {
            show:true,
            location: 'ne',
            border: '0',
            background: '#'
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#d3d3d3',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#d3d3d3',     // CSS color spec for border around grid.
            borderWidth: 0,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
         },
      });
   }  

   $(window).resize(function(){
      $.each(charts, function(i, c){
         c.replot( { resetAxes: { xaxis: true } } );
      });
   });
});
</script>